<?php
class Validator {

	function negative($p) {
		if ($p == 1){
			return 0;
		} else {
			return 1;
		}
	}

	function validateAlpha($value){
		$value=trim($value);
		$pass=preg_match('/^[a-zA-Z-]+$/', $value);
		return $this->negative($pass);
	}

	function validateNumeric($value){
		$value=trim($value);
		$pass=preg_match('/^[0-9]+$/', $value);
		return $this->negative($pass);
	}

	function validateMixed($value){
		$value=trim($value);
		//echo ini_get('magic_quotes_gpc')."s";
		//$value=ini_get('magic_quotes_gpc') ? stripslashes($value) : $value;
		$pass=preg_match('/^[a-zA-Z0-9\s]+$/', $value);
		return $this->negative($pass);
	}

	function validatePhone($value){
		$value=trim($value);
		$pass=preg_match('/^[\d]{3}[-]{1}[\d]{3}[-]{1}[\d]{4}$/', $value);
		return $this->negative($pass);
	}

	function validatePassword($value) {

		$pass = $this->validateMixed($value);
		if ($pass == 0) { // OK
			if (strlen($value) < 5 || strlen($value) >12) {
				$pass = 1;
			}
		}
		return $pass;
	}

	function validateUsername($value) {
		$pass = $this->validateMixed($value);
		if ($pass == 0) { // OK
			if (strlen($value) < 5 || strlen($value) >16) {
				$pass = 1;
			}
		}
		return $pass;
	}

	function validateEmail($value){
		$value=trim($value);
		$pass=preg_match('/^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/', $value);
		return $pass;
	}

}

?>
